
/***************滑动到顶部*****************/
$(".zc-toolbar-tabbar > .toTop").click(function(){
	
	document.documentElement.scrollTop = 0;
	
});


/******************浮动搜索框的显示和隐藏*****************/
var h1 = $(".header h1");
window.onscroll = function(){
	var st = document.documentElement.scrollTop || document.body.scrollTop;
	
	if(st >= 600){
		
		$(".header").css({
			"position":"fixed",
			"left":0,
			"top":0,
			"z-index":1790,
			"width":"100%",
			"box-shadow":"0 1px 5px rgba(0,0,0,0.1)",
			"border-bottom":"1px solid #ededed",
			"padding":"10px 0"
		});
		
		$(".header h1")[0].className = "fixed-logo";
		
	}else{
		
		$(".header").css({
			"position":"static",
			"z-index":0,
			"box-shadow":"none",
			"border-bottom":"none",
			"padding":"30px 0"
		});
		
		$(h1).css({
			"float":"left",
			"margin-top":"5px"
		});
		$(".header h1")[0].className = "logo";
	}
	
}


/****************全功能遮罩****************/
$(".apple-active-inner-close").click(function(){
	
	$(".apple-active").css("display","none");
	
});

/*设置上部导航的点击效果*/
$("li:has(.zc-hd)").css({"padding-right":22});

	$("li:has(.zc-hd)").mouseover(function(){
		
		$(this).css({"background":"white"});
		
		$(this).children("div").stop().slideDown();
		
	}).mouseout(function(){
		
		$(this).css({"background":""});
		$(this).children("div").stop().slideUp();
		
});


/*设置城市列表的点击效果和显示效果*/
$(".city-location").mouseover(function(){
	
	$(".city-location").children(".city-list").stop().slideDown();
	
}).mouseout(function(){
	
	$(".city-location").children(".city-list").stop().slideUp();
	
});

$(".city-list > li").mouseenter(function(){
	
	$(this).children("a").css({"background":"#e6e6e6","color":"#ce1a1b"});
	
}).mouseleave(function(){
	
	$(this).children("a").css({"background":"","color":"#333"});
	
}).click(function(){//点击改变样式，并收起列表
	
	$(".city-list > li").map(function(index,elem){
		$(elem).children("a")[0].className = "";
	});
	
	var str = $(this).children("a")[0].innerText;
	var name = $(".city-name")[0];
	name.innerHTML = str+"<em class=icon></em>";
	$(this).children("a")[0].className = "cur";
	$(".city-location").children(".city-list").stop().slideUp();
	
});

/****************************轮播图滑动***********************/
var ullis = Array.from(lunboUL.children);
var ollis = Array.from(lunboOL.children);

ollis.forEach(function(li,lap){
	
	li.onclick = function(){
		index = lap;
		tab();
	}
	
});

//定义全局变量，记录轮播图滚动到当前图片的下标
var index = 0;
tab();

function tab(){
	
	ollis.forEach(function(li,lap){
		
		li.className = "";
		$("#lunboUL > li").eq(lap).stop().fadeOut();
		
	});
	
	ollis[index].className = "selected-olli";
	$("#lunboUL > li").eq(index).stop().fadeIn();
}

/*切换*/
function next(){
	
	index ++;
	
	if(index == 3){
		
		index = 0;
	}
	
	tab();
}

var timer = setInterval(next,5000);

var div = $(".bx-viewport")[0];

$(div).mouseenter(function(){
	
	clearInterval(timer);
});

$(div).mouseleave(function(){
	
	timer = setInterval(next,5000);
	
});

$("#arrowSp1").click(function(){
	
	index --;
	
	if(index == -1){
		
		index = 2;
	}
	
	tab();
});

$("#arrowSp2").click(function(){
	
	next();
});



/****************中间第三层同城购*********************/
$(".function-icon:has(.function-icon_hover)").bind("mouseenter",function(){
	
	$(this).children("div").children("p").stop().animate({
		"width":62
	},500);
	
}).bind("mouseleave",function(){
	
	$(this).children("div").children("p").stop().animate({
		"width":0
	},500);
	
});

/****************中间第四层智选*********************/

/*左侧菜单切换*/
var swLis = Array.from(swSide.children);

swLis.forEach(function(li,lap){
	
	li.onmouseover = function(){
		ind = lap;
		switc();
	}
	
});

var ind = 0;
switc();

function switc(){
	
	swLis.forEach(function(li,lap){
		
		$("#swSide > li").eq(lap).css({
			
			"background":"#ececec",
			"color":"#000"
		});
		
		var img = $("#swSide > li").eq(lap).children("a").children("img");
		$(img).css({
			"display":"none"
		});
		
	});
	
	$("#swSide > li").eq(ind).css({
			
			"background":"#ce1a1b",
			"color":"#fff"
	});
	
	var img = $("#swSide > li").eq(ind).children("a").children("img");
	$(img).css({
		"display":"block",
		"top":-47*ind
	});
	
}

/***********第六层************/
/*热门导航切换*/
var hLis = Array.from($(".column-hd .column-hd_tab > li"));
var hDivs = Array.from($(".gaming_hot .column-con > div"));

hLis.forEach(function(li,b){
		
		li.onclick = function(){
			Hl = b;
			changeL();
		}
});

var Hl = 0;
changeL();

function changeL(){
	
	hLis.forEach(function(li,b){
		
		li.className = "";
		
		hDivs[b].style.display = "none";
		
	});
	hLis[Hl].className = "cut";
	hDivs[Hl].style.display = "block";
}

/****************************************热门轮播图切换***********************/
/**电竞主机轮播图切换**/
var vul1 = $(".viewport-ul1").eq(0);
var vol1 = $(".state-ol1").eq(0);

var vullis1 = Array.from($(vul1).children("li"));
var vollis1 = Array.from($(vol1).children("li"));

vollis1.forEach(function(li,lap){
	
	li.onclick = function(){
		cur1 = lap;
		viewport1();
	}
	
});

var cur1 = 0;
viewport1();

function viewport1(){
	
	vollis1.forEach(function(li,lap){
		li.className = "";
	});
	vollis1[cur1].className = "state";
	
	$(vul1).css({
		
		"left":-cur1*594,
		
	});
}

function vNext1(){
	
	cur1 ++;
	
	if(cur1 == 2){
		
		cur1 = 0;
	}
	
	viewport1();
}

var vTimer1 = setInterval(vNext1,5000);

$(".viewport-ul1").mouseenter(function(){
	
	clearInterval(vTimer1);
	
}).mouseleave(function(){
	
	vTimer1 = setInterval(vNext1,5000);
});

$(".state-ol1").mouseenter(function(){
	
	clearInterval(vTimer1);
	
}).mouseleave(function(){
	
	vTimer1 = setInterval(vNext1,5000);
});


/**电竞外设轮播图切换**/
var vul2 = $(".viewport-ul2").eq(0);
var vol2 = $(".state-ol2").eq(0);

var vullis2 = Array.from($(vul2).children("li"));
var vollis2 = Array.from($(vol2).children("li"));

vollis2.forEach(function(li,lap){
	
	li.onclick = function(){
		cur2 = lap;
		viewport2();
	}
	
});

var cur2 = 0;
viewport2();

function viewport2(){
	
	vollis2.forEach(function(li,lap){
		li.className = "";
	});
	vollis2[cur2].className = "state";
	
	$(vul2).css({
		
		"left":-cur2*594,
		
	});
}

function vNext2(){
	
	cur2 ++;
	
	if(cur2 == 3){
		
		cur2 = 0;
	}
	
	viewport2();
}

var vTimer2 = setInterval(vNext2,5000);

$(".viewport-ul2").mouseenter(function(){
	
	clearInterval(vTimer2);
	
}).mouseleave(function(){
	
	vTimer2 = setInterval(vNext2,5000);
});

$(".state-ol2").mouseenter(function(){
	
	clearInterval(vTimer2);
	
}).mouseleave(function(){
	
	vTimer2 = setInterval(vNext2,5000);
});


/**游戏本轮播图切换**/
var vul3 = $(".viewport-ul3").eq(0);
var vol3 = $(".state-ol3").eq(0);

var vullis3 = Array.from($(vul3).children("li"));
var vollis3 = Array.from($(vol3).children("li"));

vollis3.forEach(function(li,lap){
	
	li.onclick = function(){
		cur3 = lap;
		viewport3();
	}
	
});

var cur3 = 0;
viewport3();

function viewport3(){
	
	vollis3.forEach(function(li,lap){
		li.className = "";
	});
	vollis3[cur3].className = "state";
	
	$(vul3).css({
		
		"left":-cur3*594,
		
	});
}

function vNext3(){
	
	cur3 ++;
	
	if(cur3 == 3){
		
		cur3 = 0;
	}
	
	viewport3();
}

var vTimer3 = setInterval(vNext3,5000);

$(".viewport-ul3").mouseenter(function(){
	
	clearInterval(vTimer3);
	
}).mouseleave(function(){
	
	vTimer3 = setInterval(vNext3,5000);
});

$(".state-ol3").mouseenter(function(){
	
	clearInterval(vTimer3);
	
}).mouseleave(function(){
	
	vTimer3 = setInterval(vNext3,5000);
});

/**************************登录检测*************************/
var uSpan = document.getElementById("zc-login");
var aSpan = document.getElementById("zc-register");

if(getCookie("user")){
	
	var obj = getCookie("user");
	uSpan.innerHTML = "您好，"+"<a href='#'>"+obj.name+"</a>";
	aSpan.innerHTML = "<a id='log-out' class='log-out'>退出</a>"
	
	var oSpan = document.getElementById("log-out");
	oSpan.onclick = function(){
		
		//清除登录数据，刷新当前页面
		setCookie("user",null,0);
		window.location.href="index.html"
	}
	
	$("#shop-cart-num").click(function(){
		
		window.location.href="shopCart.html";
	})
	
	$("#shop-cart").click(function(){
		
		window.location.href="shopCart.html";
	})
	
	/*******************购物车检测**********************/
	if(getCookie("cartList")){
		
		var ary = Array.from(getCookie("cartList").list);
		
		$("#shop-cart-num").html("购物车"+ary.length+"件");
		
		$("#shop-cart-num2").html(ary.length);
		
	}else{
		
		$("#shop-cart-num").html("购物车0件");
		$("#shop-cart-num2").html(0);
	}
	
	
}else{
	
	$("#shop-cart-num").html("购物车0件");
	$("#shop-cart-num2").html(0);
	
	$("#shop-cart-num").click(function(){
		
		window.location.href="login.html";
	})
	
	$("#shop-cart").click(function(){
		
		window.location.href="login.html ";
	})
	
}





